#ifndef GlobalsH
#define GlobalsH

  #define _free( x ) if ( x ) { free( x ); x = NULL; }
  #define WGET(x, y) *(WORD *)&x[y]
  #define LGET(x, y) *(LONG *)&x[y]  

  #define LRAM( x ) *(LONG *)&ram[ x ]
  #define WRAM( x ) *(WORD *)&ram[ x ]

  #define TEXT_ENTRIES 0x1000  

  #include <vcl.h>
  #include <stdio.h>
  #include <conio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <dir.h>
  #include <ctype.h>  


  typedef struct _REGZ
  { //
    WORD x;
    WORD y;
    WORD a;
    BYTE stack;
  } TREG;

  typedef struct _TFRM
  { //
    LONG lpFontOffset;  
    WORD cpl;
    BYTE height;
    BYTE width;
    BYTE bpp;
    BYTE inc;
    BYTE set[4];
  } TMAP;

  typedef struct TEXTBUF
  { //
    long posi;
    long ptr_posi;
    long ptr_index;
    long tpos;
    LONG rom_posi;
    LONG pntr;
    WORD data;
    WORD ypos;
    WORD xpos;
    WORD Max_ptrs;
    BYTE tile[256];
//    WORD *TextBuf;
    BYTE *TextBuf;
    BYTE tColor;
    BYTE index;
    BYTE ColorCount;
  } TBUF;

  typedef struct TMENUMAP
  {
     BYTE menu[128][128];
     WORD Ydim,
          Xdim,
          Ypos,
          Xpos;
  } TMEN;

  typedef struct _CODE
  { //
    WORD length;
    BYTE color;
    BYTE type;
    BYTE *text;
  } CODE;

  typedef struct TTEXTBOX
  {
     WORD *pic;//[0x300*304];
     WORD Ypos,
          Xpos,
          width,
          height;
  } TBOX;

  typedef struct TROMDATA
  {
    LONG Length;
    LONG Header;
    BYTE *data;
    bool Modified;
  } TROM;

  typedef struct TPTRDATA
  {
    LONG pointer;
    LONG Length;
    LONG Position;
    BYTE *Buffer;
  } TPTR;

  typedef struct TTABLEDATA
  {
    char *tbl[0x00100];
    char *dte[0x00100];
    char *dbl[0x00300];
  } TTBL;

  typedef struct _TEXTDATA
  {
    LONG blStart;         // Start position for Pointer Table
    LONG blMaximum;       // Maximum location to insert
    LONG txOffset;        // current insertion point
    LONG rmLof;           // ROM Length of file
//    WORD ptData[0x4000];  // Pointer Table
    WORD *ptData;  // Pointer Table
    WORD txPtrIndex;      // Current string / pointer
    //------------------
    BYTE *rom;            // ROM buffer
  } TXTD;

  typedef struct PATCHER
  {
    long lof,
         ofs;
    WORD sze;
    BYTE dat;
    char fil[260];
    char rfl[260];
    BYTE *rom;
  } TPAT;

  extern LONG *lpTxtBlocks;//[0x100];
  extern LONG *lpTxtPoints;//[0x100];
  extern LONG *lpTextStart;//[0x100];
  extern LONG *lpTxtMaxPos;//[0x100];

  extern Graphics::TBitmap *Vga;
  extern char dirc[512];
  extern char txtf[512];
  extern char romf[512];
  extern char cur_dir[MAXPATH];
  //
  extern long FoundAt;
  extern WORD *ScrBuf;
  extern BYTE *ram;
//  extern BYTE *rom;
  extern BYTE *tiles;
  extern TMAP map;
  extern TBUF txt;
  extern TROM rom;
  extern TREG reg;
  extern TMEN men;
  extern TPAT ips;
  extern TTBL table;
  extern TBOX textbox[2];

  extern LONG cur_str;

  extern int  StartPos;
  extern int  ToEnd;
  extern int  curLine;
  extern int  indexLine;
  extern int  WinX;
  extern int  WinY;
  extern BYTE *EStr; //[0x1000];
  extern CODE codes[0x00100];
  extern CODE duals[0x10000];
//  extern WORD EStr[0x1000];
  extern bool iCanDraw;
  extern bool isActive;  

  extern LONG GetIndex( char *strg );
  extern void Dec2Bin( BYTE *string, LONG valu, BYTE size );
  extern long Snes2Pc( long ofs );
  extern long Pc2Snes( long ofs );
  extern long FileSize( FILE *tf );
  extern void MenuMap( WORD *Dest, TMEN *map, int Width, bool type );
  extern void memcpyw( WORD *Dest, WORD *Srce, long lcSize, char type );
  extern void memsetw( WORD *Dest, WORD Data, long lcSize );
  extern void puttile( WORD *Dest, WORD *Srce, char y, char x, int Width, bool mask );
  extern void Shift( BYTE *pic, int  h, int  w );  

  #include "FS2_Main.h"
  #include "dos5x5.h"
  #include "Menu.h"  
  #include "TextEdit.h"
  #include "KanaString.h"  
  #include "HexData.h"
  #include "ListBlock.h"      

#endif
